package com.ap.core.business.message.domain.translators.header.impl;

import com.ap.core.business.message.domain.translators.AbstractHeaderTranslator;
import com.ap.core.business.message.domain.translators.BindingListener;
import com.ap.core.business.message.domain.translators.BindingMetaData;
import com.ap.core.common.types.InputMessageType;
import com.ap.core.domain.ApMessage;
import com.ap.core.domain.OrderPayment;
import com.ap.core.exception.BusinessFailureException;
import com.ap.core.message.managepayment.info.ConfirmPaymentRequestMessageInfo;
import org.joda.time.LocalDate;

/**
 * User: Rohit.Dixit
 * Implementation class for {@link com.ap.core.business.message.domain.translators.Translator}
 */
public class ConfirmPaymentMsgHdrTranslator extends AbstractHeaderTranslator<ConfirmPaymentRequestMessageInfo> {


    @Override
    public void translate(ConfirmPaymentRequestMessageInfo boundObject, BindingMetaData metaData, BindingListener bindingListener) throws BusinessFailureException {
        final InputMessageType inputMessageType = metaData.getInputMessageType();
        final OrderPayment originalOrderPayment =  orderPaymentDao.getReadOnlyOrderPaymentByApTranId(boundObject.getPaymtDetails().getApTransactionId());
        final String reconciliationCycleId = originalOrderPayment == null ? metaData.getReconciliationInfo().getReconciliationCycleId() : originalOrderPayment.getReconciliationCycleId();
        final LocalDate reconciliationDate =  originalOrderPayment == null ? metaData.getReconciliationInfo().getReconciliationDate() : originalOrderPayment.getReconciliationDate();
        final ApMessage apMessage = populateApEvent(inputMessageType, reconciliationCycleId, reconciliationDate , boundObject.getMsgHdr().getMsgId(), boundObject.getMsgHdr().getMsgTimestamp(), boundObject.getConsumerAcct().getFIId()) ;
        bindingListener.onApMessage(apMessage, originalOrderPayment);
    }

}
